package com.bml.client.secret.demo.aqs;

import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockDemo {
   static  int sum = 0;
    public static void main(String[] args) throws InterruptedException {
        ReentrantLock lock = new ReentrantLock();

        for (int i = 0; i < 3; i++) {
            new Thread(()->{
                lock.lock();
                try{
                    for (int j = 0; j < 1000; j++) {
                        sum ++;
                    }
                }catch (Exception e){

                }finally {
                    lock.unlock();
                }

            },"Thread-"+i).start();
        }
        Thread.sleep(2000);
        System.out.println(sum);
    }
}
